$(document).ready(function() {
	var timestamp = new Date().getTime();
	$("#verifyImage").attr("src", "/iac/random/code?" + timestamp);
	$("#verifyImage").load(function() {
		$.ajax({
			type : 'get',
			url : '/iac/random/getCode?' + timestamp,
			dataType : 'json',
			success : function(data) {
				$("#voicepath").val(data.path);
			}
		});
	});

	$("#verifyImage").click(function() {
		var timestamp = new Date().getTime();
		$("#verifyImage").attr("src", "/iac/random/code?" + timestamp);
	});
})

var hint = "如需继续提供错误提示信息！请选择【确定】; 若不提供！请选择【取消】";
var flag = true;
function submitPage() {
	var name = $.trim($("#name").val()); // 姓名
	var gender = $("input[name='gender']:checked").val(); // 性别
	var phone = $.trim($("#phone").val()); // 联系电话
	var adress = $.trim($("#adress").val()); // 通讯地址
	var password = $.trim($("#password").val()); // 密码
	var affirmpassword = $.trim($("#affirmpassword").val()); // 确认密码
	var designation = $.trim($("#designation").val()); // 被投诉方名称
	var city = $("#city option:selected").val(); // 区
	var local = $.trim($("#local").val());// 被投诉方地址
	var number = $.trim($("#number").val()); // 被投诉方联系电话
	var goods = $("input[name='goods']:checked").val(); // 被投诉商品
	var goods_name = $("#goods_name").val(); // 商品名称
	var look_into = $("input[name='look_into']:checked").val(); // 查处
	var award = $("input[name='award']:checked").val(); // 奖励
	var secrecy = $("input[name='secrecy']:checked").val(); // 保密
	var communication = $("input[name='communication']:checked").val(); // 查处结果沟通
	var investigate = $("input[name='investigate']:checked").val(); // 举报人协助查处
	var year = $("#year option:selected").val(); // 年
	var month = $("#month option:selected").val(); // 月
	var day = $("#day option:selected").val(); // 日
	var content = $.trim($("#content").val()); // 简要情况
	var code = $.trim($("#code").val()); // 验证码
	
	if (name.length >= 25) {
		if (flag == true) {
			alert("您的姓名长度不能超过25");
			show_confirm();
		}
		$("#name").focus();
		return false;
	}
	if (phone.length >= 100) {
		if (flag == true) {
			alert("您的联系电话长度不能超过100");
			show_confirm();
		}
		$("#phone").focus();
		return false;
	}		
	if (adress.length >= 100) {
		if (flag == true) {
			alert("您的通讯地址长度不能超过100");
			show_confirm();
		}
		$("#adress").focus();
		return false;
	}	
	
	if (password.length >= 10) {
		if (flag == true) {
			alert("密码长度不能超过10");
			show_confirm();
		}
		$("#password").focus();
		return false;
	}	
	
	if (affirmpassword.length >= 10) {
		if (flag == true) {
			alert("确认密码长度不能超过10");
			show_confirm();
		}
		$("#affirmpassword").focus();
		return false;
	}	
	if (designation == "" || designation == "请输入名称") {
		if (flag == true) {
			alert("请输入被举报方名称");
			show_confirm();
		}
		$("#designation").focus();
		return false;
	}	
	if (designation.length >= 100) {
		if (flag == true) {
			alert("被举报方名称长度不能超过100");
			show_confirm();
		}
		$("#designation").focus();
		return false;
	}	

	if (local == "" || local == "请输入地址") {
		if (flag == true) {
			alert("请输入被举报方地址");
			show_confirm();
		}
		$("#local").focus();
		return false;
	}	
	if (local.length >= 100) {
		if (flag == true) {
			alert("被举报方地址长度不能超过100");
			show_confirm();
		}
		$("#local").focus();
		return false;
	}	
	if (number.length >= 100) {
		if (flag == true) {
			alert("被举报方联系电话长度不能超过100");
			show_confirm();
		}
		$("#number").focus();
		return false;
	}	
	if (goods_name == "" || goods_name == "请输入商品或服务名称") {
		if (flag == true) {
			alert("请输入商品或服务名称");
			show_confirm();
		}
		$("#goods_name").focus();
		return false;
	}
	
	if (goods_name.length >= 100) {
		if (flag == true) {
			alert("输入商品或服务名称长度不能超过100");
			show_confirm();
		}
		$("#goods_name").focus();
		return false;
	}		
	if (content == "" || content == "请不要超过400个汉字（包括标点）") {
		if (flag == true) {
			alert("请输入简要内容");
			show_confirm();
		}
		$("#content").focus();
		return false;
	}	

	if (content.length >= 400) {
		if (flag == true) {
			alert("简要内容长度不能超过400");
			show_confirm();
		}
		$("#content").focus();
		return false;
	}
	if (code == "" || code == "请输入验证码") {
		if (flag == true) {
			alert("请输入验证码");
			show_confirm();
		}
		$("#code").focus();
		return false;
	}	
	if (name == document.getElementById("name").defaultValue) {
		name = "";
	}
	if (phone == document.getElementById("phone").defaultValue) {
		phone = "";
	}
	if (adress == document.getElementById("adress").defaultValue) {
		adress = "";
	}
	if (password == document.getElementById("password").defaultValue) {
		password = "";
	}
	if (affirmpassword == document.getElementById("affirmpassword").defaultValue) {
		affirmpassword = "";
	}
	if (number == document.getElementById("number").defaultValue) {
		number = "";
	}	
	$.ajax({
		type : 'post',
		url : '/iac/web/reportSubmit',
		data : {
			"name" : name,
			"gender" : gender,
			"phone" : phone,
			"adress" : adress,
			"password" : password,
			"affirmpassword" : affirmpassword,
			"designation" : designation,
			"city" : city,
			"local" : local,
			"number" : number,
			"goods" : goods,
			"goods_name" : goods_name,
			"look_into" : look_into,
			"award" : award,
			"secrecy" : secrecy,
			"communication" : communication,
			"investigate" : investigate,
			"year" : year,
			"month" : month,
			"day" : day,
			"content" : content,
			"code" : code
		},
		dataType : 'json',
		success : function(data) {
			if (data.notice == true) {
				alert(data.message + " 查询编号为: " + data.id);
				location.reload();
				return false;
			} else {
				alert(data.message);
				return false;
			}
		}
	});
	return false;
}

function show_confirm() {
	var r = confirm(hint);
	if (r == false) {
		flag = false;
	}
}